package org.msb.accentis.data.util;

import java.math.BigDecimal;

import org.msb.accentis.data.pojo.Account;
import org.msb.accentis.data.pojo.Category;
import org.msb.accentis.data.pojo.Transaction;
import org.msb.accentis.data.pojo.TransactionDetail;

public class TransactionHelper {

	public static BigDecimal getTransactionValueForAccount(Transaction transaction, Account account) {
		BigDecimal amount = BigDecimal.ZERO;
		
		for (TransactionDetail detail : transaction.getTransactionDetails())
			if (detail.getAccount().equals(account))
				amount = amount.add(detail.getValue());
		
		return amount;
	}
	
	public static Category getActualCategory(Category parentCategory, Category subCategory) {
		if (null == subCategory)
			return parentCategory;
		
		return subCategory;
	}
}
